package net.stogi.unicore.beyond.io.input.core;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;

import net.stogi.unicore.beyond.api.model.PropertyValue;

public class PropertyUtils {

	private PropertyUtils() {}

	public static Boolean asBoolean(PropertyValue property) {
		return Boolean.parseBoolean(property.getValue());
	}

	public static Date asDate(PropertyValue property, DateFormat format) {
		try {
			return format.parse(property.getValue());
		}
		catch (ParseException e) {
			return null;
		}
	}

	public static Double asDouble(PropertyValue property) {
		try {
			return Double.parseDouble(property.getValue());
		}
		catch (NumberFormatException e) {
			return null;
		}
	}

	public static Integer asInteger(PropertyValue property) {
		try {
			return Integer.parseInt(property.getValue());
		}
		catch (NumberFormatException e) {
			return null;
		}
	}

	public static String asString(PropertyValue property) {
		return property.getValue();
	}
}
